package com.qianji.petmall.order.vo;

import lombok.Data;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

/**
 * @author liang zai
 * @date 2022/4/24 17:35
 * @description
 */
@Data
public class OrderConfirmVo {
    //收货地址列表
    List<MemberAddressVo> address;
    //所有选中的购物项
    List<OrderItemVo> itemVos;
    //优惠券
    Integer integration;
    //订单总额
    BigDecimal total;
    //应付金额
    BigDecimal payPrice;
    //防重复提交令牌
    String orderToken;
    //商品库存
    Map<Long,Boolean> hasStock;

    public Integer getCount(){
        Integer i = 0;
        for (OrderItemVo item:itemVos) {
            i += item.getCount();
        }
        return i;
    }

    public BigDecimal getTotal() {
        BigDecimal decimal = new BigDecimal("0");
        for (OrderItemVo item:itemVos) {
            BigDecimal multiply = item.getPrice().multiply(new BigDecimal(item.getCount().toString()));
            decimal = decimal.add(multiply);
        }
        return decimal;
    }

    public BigDecimal getPayPrice() {
        return getTotal();
    }
}
